package com.xmy.cultivate.mapper;

import com.xmy.cultivate.entity.OrderApplyAffirm;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author hpiggy
 * @since 2023-03-09
 */
public interface OrderApplyAffirmMapper extends BaseMapper<OrderApplyAffirm> {


    @Delete("DELETE from order_apply_affirm where order_id = ${orderId} and affirm_type = ${affirmType} and type = ${type}")
    public Integer delAffirm(@Param("orderId") Long orderId,@Param("affirmType") Integer affirmType,@Param("type") Integer type);

    @Delete("DELETE from order_apply_affirm where order_id = ${orderId} and type = ${type}")
    public Integer delAffirmForType(@Param("orderId") Long orderId,@Param("type") Integer type);



    @Select("select * from order_apply_affirm where order_id = ${orderId} and type = ${type} ORDER BY created_at,id desc limit 1")
    public OrderApplyAffirm getOneForNew(@Param("orderId") Long orderId,@Param("type") Integer type);

    @Select("select * from order_apply_affirm where order_id = ${orderId} and affirm_type = ${affirmType} and type = ${type} ORDER BY created_at,id desc limit 1")
    public OrderApplyAffirm getOneForOrderId(@Param("orderId") Long orderId,@Param("affirmType") Integer affirmType,@Param("type") Integer type);

    @Select("select * from order_apply_affirm where order_id = ${orderId} and type =1 order by id desc")
    public List<OrderApplyAffirm> getListForOrderId(@Param("orderId") Long orderId);

    @Select("select affirm_type from order_apply_affirm where order_id = ${orderId} and type =1 order by id desc")
    public List<Integer> getAffirmTypeListForOrderId(@Param("orderId") Long orderId);

}
